package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.domain.Parking;
import com.ruoyi.system.domain.Vehicle;
import com.ruoyi.system.domain.dto.ParkingDto;
import com.ruoyi.system.domain.vo.ParkingVo;
import com.ruoyi.system.domain.vo.VehicleVo;
import com.ruoyi.system.service.ParkingService;
import com.ruoyi.system.mapper.ParkingMapper;
import com.ruoyi.system.service.VehicleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author 22115
* @description 针对表【parking】的数据库操作Service实现
* @createDate 2025-02-18 13:48:43
*/
@Service
public class ParkingServiceImpl extends ServiceImpl<ParkingMapper, Parking>
    implements ParkingService{

    @Resource
    VehicleService vehicleService;
    @Override
    public AjaxResult ParkingList(ParkingDto parkingDto) {
        Page<Parking> parkingPage = new Page<>(parkingDto.getPageNum(), parkingDto.getPageSize());

        Page<ParkingVo> parkingVoPage = new Page<>(parkingDto.getPageNum(), parkingDto.getPageSize());

        LambdaQueryWrapper<Parking> parkingLambdaQueryWrapper = new LambdaQueryWrapper<>();
        parkingLambdaQueryWrapper.eq(Parking::getStatus,0);


        Page<Parking> page = this.page(parkingPage, parkingLambdaQueryWrapper);

        List<ParkingVo> parkingVos = new ArrayList<>();
        List<Parking> records = page.getRecords();
        for (int i = 0; i < records.size(); i++) {
            ParkingVo parkingVo = new ParkingVo();
            BeanUtils.copyBeanProp(parkingVo,records.get(i));
            Vehicle byId = vehicleService.getById(records.get(i).getVehicleId());
            //获取车牌号
            parkingVo.setVehicleName(byId.getCarNumber());

            //
            parkingVos.add(parkingVo);
        }

        parkingVoPage.setRecords(parkingVos);
        return AjaxResult.success(parkingVoPage);   }
}




